package com.cskaoyan._03api;

import java.util.Arrays;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/16 10:19
 **/
/*
其他功能
 */
public class Demo4 {
    public static void main(String[] args) {
        //String类的替换功能
        //在新的字符串中，用新(new)字符，替换旧(old)字符  "abcd"
        //String replace(char old,char new)
        //
        //在新的字符串中，用新的字符串(new), 替换旧(old)字符串
        //String replace(String old, String new)
        String s = "abcdef";

        String s1 = s.replace("ab", "mm");
        System.out.println(s1);

        String s2 = "aaaaa ";
        String s3 = s2.replace(" ", "");
        System.out.println(s3);

        //在新的字符串中，去掉开头和结尾的空格字符 "abc"  "abc "
        //String trim()

        String s4 = s2.trim();
        System.out.println("s4 = " + s4);

        //分隔功能
        //将字符串按照符号分隔成字符串数组  "a,b,c,d"
        //String[] split(String re)
        // String s5 = "a,b,c,d";
        String s5 = "a=b=c=d";
        //String[] strings = s5.split(",");
        String[] strings = s5.split("=");
        System.out.println(Arrays.toString(strings));


        //String类的比较功能
        //int compareTo(String str)
        //int compareToIgnoreCase(String str)
        String str1 = "ac";
        String str2 = "ac";
        int i = str1.compareTo(str2);
        //int i = str2.compareTo(str1);
        System.out.println(i);

    }
}
